import { modal } from '@hs-admin/utils'
import { Button, Descriptions, DescriptionsProps, Empty, Flex, Image, Modal, Tooltip } from 'antd'
import { ForwardRefRenderFunction, forwardRef, memo, useImperativeHandle, useState } from 'react'
import {
  getBiddingEventDetail,
  getCommonEventDetail,
  getSoftwareDetail,
  getIcpRecordDetail,
  getCompanyCertDetail,
  getCompanyAbroadDrugDetail
} from '@/api/companyDetail/detail'
import { getEventTableType, getValidType } from '@/utils/type'
import { hsHandleTableDate, hsHandleTableDateTime } from '@hs-admin/utils'
import { EMPTYTEXT } from '@hs-admin/utils'
import { filterContentHtml, openCompanyDetail } from 'hs-react-company'

interface Props {}
const DetailModal: ForwardRefRenderFunction<unknown, Props> = (_props: Props, ref: any) => {
  const [isModalOpen, setIsModalOpen] = useState(false)
  const [modalTitle, setmodalTitle] = useState('')
  const [title, settitle] = useState('')
  const [dataList, setdataList] = useState<any[]>([])
  const isImg = (url: string | string[]) => {
    return url.includes('.jpg') || url.includes('.png') || url.includes('.jpeg') || url.includes('.JPG')
  }
  const items: DescriptionsProps['items'] = dataList.map((item) => ({
    ...item,
    key: item.label,
    span: !item.span || item.span === 1 ? 2 : item.span,
    children: (
      <>
        {item.value && typeof item.value === 'string' && isImg(item.value) && <Image width={100} src={item.value} />}
        {item.type === 'view-content' && typeof item.value === 'string' && (
          <Tooltip title={item.value}>
            <Button type="link" onClick={() => openViewContent(item)}>
              {item.value}
            </Button>
          </Tooltip>
        )}
        {item.type === 'link' && typeof item.value === 'string' && (
          <Tooltip title={item.value}>
            <Button type="link" onClick={() => toLink(item)}>
              <p className="max-w-146 single-text-overflow">{item.value}</p>
            </Button>
          </Tooltip>
        )}
        {item.type === 'link' && Array.isArray(item.value) && (
          <Flex wrap="wrap">
            {item.value.map((second: { company_name: string; company_code: string }) => (
              <Button
                type="link"
                key={second.company_name}
                onClick={() => {
                  openCompanyDetail(second.company_code)
                }}>
                {second.company_name}
              </Button>
            ))}
          </Flex>
        )}
        {!item.type && !isImg(`${item.value}`) && <div dangerouslySetInnerHTML={{ __html: item.value }} className="max-w-160"></div>}
      </>
    )
  }))
  const [emptyFlag, setemptyFlag] = useState(false)
  const noPublish = '未公布'

  const toLink = (item: { url: any }) => {
    window.open(`${item.url}`, '_blank')
  }
  const openViewContent = (item: { content: string }) => {
    const modalInst = modal.info({
      title: '查看内容',
      content: <div className="max-h-600px overflow-y-auto">{filterContentHtml(item.content)}</div>,
      footer: null,
      closable: true,
      maskClosable: true
    })
    return modalInst
  }
  const handleCancel = () => {
    setIsModalOpen(false)
    setmodalTitle('')
    settitle('')
    setdataList([])
  }
  const detailUrl = (companyCode: string) => {
    return `/detail?companyCode=${companyCode}`
  }
  const handleOrgInfo = (data: { org_info: any[]; org_info_list: string; org_info_list_update: any[] }) => {
    data.org_info = []
    if (data.org_info_list) {
      data.org_info_list_update = JSON.parse(data.org_info_list)
      data.org_info = data.org_info_list_update?.map((ele: any) => ({
        ...ele,
        url: detailUrl(ele.company_code)
      }))
    }
  }
  const handleEmpty = (data: string | any[]) => {
    if (Array.isArray(data) && !data.length) {
      setemptyFlag(true)
    } else {
      setemptyFlag(false)
    }
  }

  useImperativeHandle(
    ref,
    () => {
      return {
        showModal: (item: any) => {
          if (item) {
            const localModalTitle = item.eventSubType
            setmodalTitle(localModalTitle)
            item.id = item.sourceId || item.id
            settitle('')
            setdataList([])
            // start
            switch (localModalTitle) {
              case '产业外溢':
              case '人事动向':
              case '安全事件':
              case '经营状况':
              case '质量风险':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: item.sourceTable || getEventTableType(localModalTitle)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    settitle(data.title)
                    handleOrgInfo(data)
                    setdataList([
                      { label: '标题', value: data.title, span: 4 },
                      { label: '发布时间', value: hsHandleTableDate(data.publish_time), span: 2 },
                      { label: '来源', value: data.site_name, span: 2 },
                      { label: '关联企业', value: data.org_info, span: 4, type: 'link' },
                      { label: '摘要', value: data.summary, span: 4 },
                      { label: '正文', value: '查看内容', span: 4, type: 'view-content', content: data.content },
                      { label: '详情链接', value: data.detail_url, span: 4, type: 'link', url: data.detail_url }
                    ])
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break
              case '产品上市':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '器械获批上市':
                        settitle(data.device_name + '获批上市')
                        if (data.org_info_list) {
                          data.org_info_list = JSON.parse(data.org_info_list)
                          data.registrant_name_code = data.org_info_list.find(
                            (ele: { company_name: any }) => ele.company_name === data.registrant_name_cn
                          )?.company_code
                          data.agent_name_code = data.org_info_list.find(
                            (ele: { company_name: any }) => ele.company_name === data.agent_name
                          )?.company_code
                        }
                        setdataList([
                          { label: '器械名称', value: data.device_name },
                          { label: '管理类别', value: data.product_category },
                          { label: '国产/进口', value: data.domestic_abroad },
                          {
                            label: '注册人',
                            value: data.registrant_name_cn,
                            type: data.registrant_name_code ? 'link' : '',
                            url: detailUrl(data.registrant_name_code)
                          },
                          { label: '注册证编号', value: data.reg_no },
                          { label: '代理人', value: data.agent_name, type: data.agent_name_code ? 'link' : '', url: detailUrl(data.agent_name_code) },
                          { label: '是否有效', value: getValidType(data.is_valid) },
                          { label: '首次获批年份', value: data.first_aprv_year + '年' },
                          { label: '批准日期', value: data.aprv_date },
                          { label: '有效期至', value: data.end_date }
                        ])
                        break
                      case '绿色建材评价':
                        settitle(data.appl_name + '的' + data.product_name + '获得绿色建材评价')
                        setdataList([
                          { label: '产品名称', value: data.product_name },
                          { label: '规格型号', value: data.spec_model },
                          { label: '生产企业', value: data.manufacturer },
                          { label: '申请人', value: data.appl_name },
                          { label: '评价机构', value: data.eva_org_name },
                          { label: '证书编号', value: data.certificate_no },
                          { label: '发证日期', value: data.approve_date },
                          { label: '有效期至', value: data.end_date },
                          { label: '评价依据', value: data.eva_basis },
                          { label: '星级', value: data.star_level },
                          { label: '评价状态', value: getValidType(data.is_valid), span: 4 }
                        ])
                        break
                      case '农机产品认证':
                        settitle(data.manufacturer + '的' + data.product_name + '产品认证信息')
                        setdataList([
                          { label: '产品名称', value: data.product_name },
                          { label: '制造商', value: data.manufacturer },
                          { label: '认证委托人', value: data.client },
                          { label: '生产企业', value: data.factory },
                          { label: '认证类型', value: data.certificate_type },
                          { label: '信息来源', value: data.info_source },
                          { label: '标准/规则', value: data.product_std },
                          { label: '有效期至', value: data.end_date },
                          { label: '首次发证日期', value: data.first_approve_date },
                          { label: '发证日期', value: data.approve_date },
                          { label: '型号/规格', value: data.spec_model },
                          { label: '证书编号', value: data.certificate_no },
                          { label: '证书状态', value: data.state },
                          { label: '证书状态变化时间', value: data.state_change_date },
                          { label: '原因', value: data.reason, span: 4 }
                        ])
                        break
                      case '新能源汽车发布':
                        settitle(data.manufacturer + '发布' + data.product_name)
                        setdataList([
                          { label: '生产商', value: data.manufacturer },
                          { label: '产品名称', value: data.product_name },
                          { label: '发布性质', value: data.publish_type },
                          { label: '发布日期', value: data.publish_date },
                          { label: '发布批次', value: data.publish_batch },
                          { label: '产品型号', value: data.product_model },
                          { label: '动力蓄电池组总能量(KWh)', value: data.battery_power },
                          { label: '动力蓄电池组总重量(KG)', value: data.battery_mass },
                          { label: '整车质量(KG)', value: data.vehicle_mass },
                          { label: '续航里程(KM)', value: data.driving_range }
                        ])
                        break
                      case '保健食品备案':
                        settitle(data.product_name + '保健食品备案信息')
                        setdataList([
                          { label: '保健食品名称', value: data.product_name, span: 4 },
                          { label: '申报企业', value: data.company_name },
                          { label: '备案号', value: data.license_no },
                          { label: '类别（标准）', value: data.classify_std },
                          { label: '备案日期', value: data.approve_date }
                        ])
                        break
                      case '药品获批上市':
                        settitle(data.drug_name + '获批上市')
                        setdataList([
                          { label: '药品名称', value: data.drug_name, span: 4 },
                          { label: '生产商', value: data.manufacturer },
                          { label: '上市许可持有人', value: data.mah },
                          { label: '药品类型', value: data.drug_type },
                          { label: '是否进口', value: '否' },
                          { label: '有效截止日期', value: data.end_date },
                          { label: '批准日期', value: data.approve_date },
                          { label: '商品名称', value: data.proprietary_name },
                          { label: '批准文号', value: data.approve_no },
                          { label: '靶点', value: data.target },
                          { label: '首次获批年份', value: data.first_aprv_year + '年' },
                          { label: '剂型', value: data.dosage_form },
                          { label: '规格', value: data.specification },
                          { label: '说明书适应症', value: data.label_indication, span: 4 }
                        ])
                        break
                      case '新兽药注册':
                        settitle(data.vet_drug_name)
                        setdataList([
                          { label: '新兽药名称', value: data.vet_drug_name },
                          { label: '新兽药注册证书号', value: data.reg_no },
                          { label: '研制单位', value: data.company_name, span: 4 },
                          { label: '最新公告时间', value: data.latest_notice_date },
                          { label: '产品类别', value: data.latest_notice_date }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break
              case '产品研发':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: item.sourceTable || getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '器械受理':
                        settitle(data.device_name + '受理信息')
                        setdataList([
                          { label: '器械名称', value: data.device_name },
                          { label: '审评结论', value: data.eva_decision },
                          { label: '受理类型', value: data.acce_type },
                          { label: '受理号', value: data.acce_no },
                          { label: '申请企业', value: data.appl_company },
                          { label: '代理人名称', value: data.agent_name },
                          { label: '当前状态', value: data.now_state },
                          { label: '当前状态开始时间', value: data.now_state_start_date },
                          { label: '管理类别', value: data.product_category },
                          { label: '受理年份', value: data.acce_year + '年' },
                          { label: '注册证号', value: data.reg_no },
                          { label: '批件通知日期', value: data.notice_date }
                        ])
                        break
                      case '新药管线':
                        settitle(data.drug_name + '申请信息')
                        setdataList([
                          { label: '药品名称', value: data.drug_name, span: 4 },
                          { label: '药品类型', value: data.drug_type },
                          { label: '申请类型', value: data.apply_type },
                          { label: '注册分类', value: data.reg_class },
                          { label: '受理类型', value: data.acce_type },
                          { label: '企业名称', value: data.company_name },
                          { label: '受理号', value: data.acce_no },
                          { label: '靶点', value: data.target },
                          { label: '适应症', value: data.clinical_indication },
                          { label: '承办日期', value: data.apply_date },
                          { label: '审评结论', value: data.eva_decision }
                        ])
                        break
                      case '药品临床试验':
                        settitle(data.drug_name + '临床试验信息')
                        setdataList([
                          { label: '药品名称', value: data.drug_name, span: 4 },
                          { label: '药品类型', value: data.drug_type },
                          { label: '试验分期', value: data.trial_stage_modify },
                          { label: '申请类型', value: data.apply_type },
                          { label: '临床登记号', value: data.reg_no },
                          { label: '申办者名称', value: data.sponsor_name },
                          { label: '试验状态', value: data.trial_state },
                          { label: '首次公示日期', value: data.first_announce_date },
                          { label: '试验完成日期', value: data.trial_end_date },
                          { label: '通俗题目', value: data.brief_title, span: 4 },
                          { label: '专业题目', value: data.official_title, span: 4 },
                          { label: '试验目的', value: data.trial_purpose, span: 4 },
                          { label: '适应症', value: data.indication, span: 4 },
                          { label: '靶点', value: data.target, span: 4 },
                          { label: '剂型', value: data.dosage_form },
                          { label: '招募状态', value: data.recruit_state },
                          { label: '设计类型', value: data.design_type },
                          { label: '试验范围', value: data.trial_range },
                          { label: '受试者年龄', value: data.subject_age },
                          { label: '受试者性别', value: data.subject_gender },
                          { label: '目标入组人数', value: data.planned_enroll_no },
                          { label: '实际入组人数', value: data.actual_enroll_no },
                          { label: '入选标准', value: data.inclusion_criteria, span: 4 },
                          { label: '排除标准', value: data.exclusion_criteria, span: 4 }
                        ])
                        break
                      case '药品优先审评':
                        settitle(data.drug_name + '优先审评信息')
                        setdataList([
                          { label: '药品名称', value: data.drug_name },
                          { label: '受理号', value: data.acce_no },
                          { label: '注册申请人', value: data.apply_name, span: 4 },
                          { label: '状态', value: data.state },
                          { label: '剂型', value: data.dosage_form },
                          { label: '规格', value: data.specification },
                          { label: '申请日期', value: data.application_date },
                          { label: '承办日期', value: data.apply_date },
                          { label: '公示日期', value: data.public_date },
                          { label: '拟适应症', value: data.proposed_indication, span: 4 },
                          { label: '拟优先审评的理由', value: data.priority_eva_reason, span: 4 }
                        ])
                        break
                      case '仿制药一致性评价':
                        settitle(data.drug_name + '一致性评价信息')
                        setdataList([
                          { label: '药品名称', value: data.drug_name },
                          { label: '通用名称', value: data.generic_name },
                          { label: '上市许可持有人', value: data.mah },
                          { label: '生产企业名称', value: data.manufacture },
                          { label: '生产企业地址', value: data.produce_address },
                          { label: '批准日期', value: data.approved_date },
                          { label: '最新批准文号', value: data.aprv_ref_no },
                          { label: '受理号', value: data.acce_no },
                          { label: '英文名', value: data.drug_name_en },
                          { label: '剂型及规格', value: data.dosage_form_spec },
                          { label: '附加申请', value: data.attach_apply },
                          { label: '临床研究豁免情况', value: data.release_from_clinic },
                          { label: 'BE备案号/临床试验批件号', value: data.be_record_clini_no },
                          { label: 'BE供试样品批号', value: data.be_test_sample_no },
                          { label: '临床研究机构', value: data.clini_org },
                          { label: '数据统计分析机构', value: data.data_anls_org },
                          { label: '生物样本检测机构', value: data.sample_test_org },
                          { label: '完成的临床研究内容', value: data.cmpl_clinic_res },
                          { label: '试验设计', value: data.exp_design, span: 4 },
                          { label: '检测物质', value: data.test_substance },
                          { label: '检测方法', value: data.test_method },
                          { label: '检测机构', value: data.test_org },
                          { label: '检验结果', value: data.test_result },
                          { label: '说明书', value: data.label_url },
                          { label: '信息公开', value: data.info_url }
                        ])
                        break
                      case '器械特殊审批':
                        settitle(data.device_name + '特殊审批信息')
                        setdataList([
                          { label: '器械名称', value: data.device_name, span: 4 },
                          { label: '申请企业', value: data.appl_company, span: 4 },
                          { label: '分类', value: data.mainclass },
                          { label: '审批类型', value: data.approve_type },
                          { label: '管理类别', value: data.product_category },
                          { label: '审核部门', value: data.department },
                          { label: '公示开始日期', value: data.start_date },
                          { label: '公示结束日期', value: data.end_date },
                          { label: '资质级别', value: data.qualified_level },
                          { label: '受理号', value: data.acce_no },
                          { label: '同意理由', value: data.agree_reason, span: 4 }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break
              case '企业荣誉':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '重大奖项':
                        settitle(data.project_name + '获得' + data.award_item + data.award_level)
                        setdataList([
                          { label: '项目名称', value: data.project_name, span: 4 },
                          { label: '奖项名称', value: data.award_item },
                          { label: '奖项等级', value: data.award_level },
                          { label: '奖项级别', value: data.award_rank },
                          { label: '奖项类型', value: data.award_type },
                          { label: '主要完成单位', value: data.company_name, span: 4 },
                          { label: '主要完成人', value: data.principal, span: 4 },
                          { label: '省份', value: data.province },
                          { label: '公布年份', value: data.report_year },
                          { label: '推荐单位', value: data.rec_company, span: 4 }
                        ])
                        break
                      case '资质证书':
                        settitle(data.company_name + '获得' + data.qualified_name + '资质')
                        setdataList([
                          { label: '企业名称', value: data.company_name, type: data.company_code ? 'link' : '', url: detailUrl(data.company_code) },
                          { label: '资质名称', value: data.qualified_name },
                          { label: '发布日期', value: data.publish_date },
                          { label: '截止日期', value: data.end_date },
                          { label: '公告标题', value: data.notice_title },
                          { label: '认定部门', value: data.department }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break
              case '企业上市':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '企业成功上市':
                        settitle(data.security_shortname + '成功上市')
                        setdataList([
                          { label: '证券简称', value: data.security_shortname },
                          { label: '交易板块', value: data.trade_plate },
                          { label: '企业名称', value: data.company_name },
                          { label: '证券代码', value: data.security_code },
                          { label: '股票代码', value: data.stock_code },
                          { label: '交易市场', value: data.trade_market },
                          { label: '上市时间', value: data.list_date },
                          { label: '上市状态', value: data.is_list === 1 ? '上市' : '退市' },
                          { label: '发行方式', value: data.issue_method },
                          { label: '首发数量（股）', value: data.ipo_num },
                          { label: '首发定价（人民币元）', value: data.ipo_price },
                          { label: '募资总额（人民币元）', value: data.act_tot_amt },
                          { label: '募资净额（人民币元）', value: data.act_amt }
                        ])
                        break
                      case '企业申请上市':
                        settitle(data.company_name || '' + '申请上市')
                        setdataList([
                          { label: '企业名称', value: data.company_name, span: 4, type: 'link', url: detailUrl(data.company_code) },
                          { label: '申报日期', value: data.declare_date },
                          { label: '证券类型', value: data.security_type },
                          { label: '拟上市地点', value: data.plan_list_plate },
                          { label: '当前状态', value: data.cur_state }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break
              case '企业并购':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '并购企业':
                      case '企业被并购':
                        settitle('关于' + data.acquiree_name + '的并购事件')
                        setdataList([
                          { label: '交易标的', value: data.trade_target, span: 4 },
                          { label: '出让方', value: data.transferor_name, span: 4 },
                          { label: '受让方', value: data.acquirer_name, span: 4 },
                          { label: '标的方', value: data.acquiree_name, span: 4 },
                          { label: '交易总价值(人民币元)', value: data.trade_value_cal },
                          { label: '标的类型', value: data.target_type },
                          { label: '开始时间', value: data.start_date },
                          { label: '结束时间', value: data.end_date },
                          { label: '交易进度', value: data.regtrade_schedule_no, span: 4 }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '企业投资':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '对外投资':
                        settitle(data.company_name + '投资' + data.inv_company_name)
                        setdataList([
                          {
                            label: '投资企业',
                            value: data.company_name,
                            span: 4,
                            type: data.company_code ? 'link' : '',
                            url: detailUrl(data.company_code)
                          },
                          {
                            label: '被投资企业',
                            value: data.inv_company_name,
                            span: 4,
                            type: data.company_code ? 'link' : '',
                            url: detailUrl(data.inv_company_code)
                          },
                          { label: '投资比例', value: data.proportion },
                          { label: '投资金额（人民币元）', value: data.inv_amt_cal },
                          { label: '被投企业成立时间', value: data.inv_found_date, span: 4 }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '企业融资':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '获得融资':
                        data.financing_amt_describe = data.financing_amt_describe === '未披露' ? '' : data.financing_amt_describe
                        settitle(data.company_name + '获得' + data.financing_round + '融资' + data.financing_amt_describe)
                        setdataList([
                          { label: '企业名称', value: data.company_name },
                          { label: '融资时间', value: data.financing_date },
                          { label: '投资方', value: data.invest_company_name, span: 4 },
                          { label: '融资金额', value: data.financing_amt_describe },
                          { label: '轮次', value: data.financing_round_std }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '工商变更':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(localModalTitle)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    settitle(data.company_name + data.change_date + data.change_type_std)
                    setdataList([
                      { label: '企业名称', value: data.company_name },
                      { label: '变更类型', value: data.change_type },
                      { label: '是否正常经营', value: data.is_normal ? '是' : '否' },
                      { label: '变更时间', value: data.change_date },
                      { label: '变更前', value: data.change_before },
                      { label: '变更后', value: data.change_after }
                    ])
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '法律风险':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '被执行人':
                        settitle(data.company_name + '被' + data.court + '执行')
                        setdataList([
                          { label: '企业名称', value: data.company_name, type: data.company_code ? 'link' : '', url: detailUrl(data.company_code) },
                          { label: '执行金额（人民币元）', value: data.target_amt },
                          { label: '法院名称', value: data.court },
                          { label: '立案时间', value: data.filing_date },
                          { label: '案号', value: data.notice_num, span: 4 }
                        ])
                        break
                      case '裁判文书':
                        settitle(data.judgment_title)
                        setdataList([
                          { label: '当事人', value: item.companyName },
                          { label: '当事人类型', value: data.party_type },
                          { label: '案由', value: data.notice_reason },
                          { label: '判决书类型', value: data.judgment_type },
                          { label: '案件类型', value: data.case_type },
                          { label: '案件金额（人民币元）', value: data.case_amt },
                          { label: '审理程序', value: data.trial_progress },
                          { label: '法院名称', value: data.court },
                          { label: '裁判日期', value: data.judgment_date },
                          { label: '发布日期', value: data.publish_date },
                          { label: '裁判结果', value: data.judgment_result, span: 4 }
                        ])
                        break
                      case '行政处罚':
                        settitle(EMPTYTEXT)
                        setdataList([
                          { label: '企业名称', value: item.companyName },
                          { label: '处罚日期', value: data.punish_date },
                          { label: '处罚单位', value: data.punish_org_name },
                          { label: '处罚事由', value: data.punish_reason },
                          { label: '处罚决定书', value: data.punish_num, span: 4 },
                          { label: '处罚结果', value: data.punish_result, span: 4 }
                        ])
                        break
                      case '开庭公告':
                        if (data.prosecutor && data.defendant) {
                          settitle(data.prosecutor + '上诉' + data.defendant + '的开庭公告')
                        } else {
                          settitle(`关于${data.defendant || data.prosecutor || ''}的开庭公告`)
                        }
                        setdataList([
                          { label: '上诉人', value: data.prosecutor },
                          { label: '被上诉人', value: data.defendant },
                          { label: '案由', value: data.notice_reason },
                          { label: '案号', value: data.notice_num },
                          { label: '开庭时间', value: data.court_time ? hsHandleTableDateTime(data.court_time) : EMPTYTEXT },
                          { label: '承办部门', value: data.undertake_dep },
                          { label: '法院名称', value: data.court },
                          { label: '法庭', value: data.courtroom },
                          { label: '开庭公告', value: data.content, span: 4 }
                        ])
                        break
                      case '失信被执行人':
                        settitle(data.company_name + '被列入失信被执行人')
                        setdataList([
                          { label: '被执行人', value: data.company_name },
                          { label: '做出执行依据单位', value: data.execute_org },
                          { label: '法院名称', value: data.court },
                          { label: '被执行人履行情况', value: data.execute_state },
                          { label: '案号', value: data.notice_num },
                          { label: '执行依据文号', value: data.execute_num },
                          { label: '立案时间', value: data.filing_date },
                          { label: '发布时间', value: data.publish_date },
                          { label: '案件金额（人民币元）', value: data.case_amt },
                          { label: '行为具体情形', value: data.action_remark },
                          { label: '生效法律文书确定的义务', value: data.content, span: 4 }
                        ])
                        break
                      case '立案信息':
                        settitle('立案信息：' + data.case_name)
                        setdataList([
                          { label: '公司名称', value: item.company_name },
                          { label: '案由', value: data.notice_reason },
                          { label: '案件类型', value: data.case_type },
                          { label: '案件金额（人民币）', value: data.case_amt },
                          { label: '案件时间', value: data.notice_year },
                          { label: '案件身份', value: data.case_identity },
                          { label: '案号', value: data.notice_num },
                          { label: '法院名称', value: data.court },
                          { label: '最新案件进程', value: data.state },
                          { label: '最新进程日期', value: data.process_date }
                        ])
                        break
                      case '法院公告':
                        if (data.prosecutor && data.defendant) {
                          settitle(data.prosecutor + '上诉' + data.defendant + '的法院公告')
                        } else {
                          settitle(`关于${data.defendant || data.prosecutor}的法院公告`)
                        }
                        setdataList([
                          { label: '上诉人', value: data.prosecutor },
                          { label: '被上诉人', value: data.defendant },
                          { label: '案由', value: data.notice_reason },
                          { label: '案号', value: data.notice_num },
                          { label: '公告类型', value: data.notice_type },
                          { label: '发布日期', value: data.publish_date },
                          { label: '法院名称', value: data.court, span: 4 }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '知识产权':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: getEventTableType(item.eventSegment)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '商标注册':
                        settitle(data.brand_name + '商标注册信息')
                        handleOrgInfo(data)
                        setdataList([
                          { label: '商标名称', value: data.brand_name },
                          {
                            label: '企业名称',
                            value: data.org_info.length ? data.org_info : item.company_name,
                            type: 'link',
                            url: !data.org_info?.length ? '' : detailUrl(item.company_code)
                          },
                          { label: '商标国际分类', value: data.classify },
                          { label: '注册号', value: data.reg_code },
                          { label: '申请日期', value: data.appl_date },
                          { label: '商标类型', value: data.brand_type },
                          { label: '商标状态', value: data.brand_state },
                          { label: '注册公告日期', value: data.reg_date },
                          { label: '商标图形', value: data.photourl, span: 4 }
                        ])
                        break
                      case '发明专利':
                      case '发明授权':
                      case '发明专利授权':
                      case '实用新型':
                        settitle(data.title + '的专利信息')
                        setdataList([
                          { label: '专利名称', value: data.title, span: 4 },
                          { label: '申请人', value: data.applicant },
                          { label: '发明人', value: data.inventor },
                          { label: '专利类型', value: data.patent_type },
                          { label: '专利状态', value: data.patent_state },
                          { label: '是否PCT专利', value: data.country === '世界知识产权组织' ? '是' : '否' },
                          { label: '法律状态', value: data.legal_state },
                          { label: '公开（公告）号', value: data.publication_code },
                          { label: '公开(公告)日期', value: data.publication_date },
                          { label: '申请号', value: data.application_code },
                          { label: '申请日期', value: data.application_date },
                          { label: '国家', value: data.country, span: 4 },
                          { label: '摘要', value: data.abstract, span: 4 }
                        ])
                        break
                      default:
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '经营风险':
                getCommonEventDetail({
                  queryId: item.id,
                  tableName: ['经营异常', '股权出质'].includes(item.eventSegment)
                    ? getEventTableType(item.eventSegment)
                    : getEventTableType(localModalTitle)
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    switch (item.eventSegment) {
                      case '经营异常':
                        settitle(EMPTYTEXT)
                        setdataList([
                          { label: '公司名称', value: item.company_name, span: 4 },
                          { label: '列入日期', value: data.in_date },
                          { label: '移除日期', value: data.out_date },
                          { label: '列入机关名称', value: data.in_org },
                          { label: '移除机关名称', value: data.out_org },
                          { label: '列入原因', value: data.in_reason },
                          { label: '移除原因', value: data.out_reason }
                        ])
                        break
                      case '股权出质':
                        settitle(data.pledger_company_name + '股权被出质给' + data.pledgee)
                        setdataList([
                          { label: '出质股权标的企业', value: data.pledger_company_name },
                          { label: '质权人', value: data.pledgee },
                          { label: '出质人', value: data.pledger },
                          { label: '质权登记编号', value: data.pledge_num },
                          { label: '股权出质登记日期', value: data.register_date },
                          { label: '出质股权数额', value: data.pledged_amt },
                          { label: '出质状态', value: data.state, span: 4 }
                        ])
                        break
                      default:
                        settitle(data.title)
                        handleOrgInfo(data)
                        setdataList([
                          { label: '标题', value: data.title, span: 4 },
                          { label: '发布时间', value: hsHandleTableDate(data.publish_time) },
                          { label: '来源', value: data.site_name },
                          { label: '关联企业', value: data.org_info, type: 'link', span: 4 },
                          { label: '摘要', value: data.summary, span: 4 },
                          { label: '正文', value: '查看内容', type: 'view-content', content: data.content, span: 4 },
                          { label: '详情链接', value: data.detail_url, span: 4, type: 'link', url: data.detail_url }
                        ])
                        break
                    }
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '招标详情':
                getBiddingEventDetail({
                  id: item.id
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    settitle(data.title)
                    setdataList([
                      { label: '采购人', value: data.buyer || noPublish },
                      { label: '供应商', value: data.suppName || noPublish },
                      { label: '招标类型', value: data.typeFirst || noPublish },
                      { label: '公告类型', value: data.typeSecond || noPublish },
                      { label: '发布日期', value: data.pubDate || noPublish },
                      {
                        label: '公告原文',
                        value: data.sourceUrl ? '去查看' : noPublish,
                        type: data.sourceUrl ? 'link' : '',
                        url: data.sourceUrl
                      }
                    ])
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '进口药品详情':
                getCompanyAbroadDrugDetail({
                  queryId: item.id,
                  tableName: 'dm_lget_abroad_drug'
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    settitle(data.drug_name)
                    setdataList([
                      { label: '生产商', value: data.manufacturer || data.manufacturer_en || noPublish },
                      { label: '药品类型', value: data.drug_name || data.drug_name_en || noPublish },
                      { label: '上市许可持有人', value: data.mah || data.mah_en || noPublish },
                      { label: '是否进口', value: '是' },
                      { label: '批准日期', value: data.approve_date || noPublish },
                      { label: '注册证号', value: data.approve_no || noPublish },
                      { label: '有效截止日期', value: data.end_date || noPublish },
                      { label: '原注册证号', value: data.orig_approve_no || noPublish },
                      { label: '商品名称', value: data.proprietary_name || data.proprietary_name_en || noPublish },
                      { label: '首次获批年份', value: data.first_aprv_year ? data.first_aprv_year + '年' : noPublish },
                      { label: '靶点', value: data.target || noPublish },
                      { label: '剂型', value: data.dosage_form || noPublish },
                      { label: '包装规格', value: data.packing_spec || noPublish },
                      { label: '规格', value: data.specification || noPublish },
                      { label: '说明书适应症', value: data.label_indication || noPublish, span: 4 }
                    ])
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '软件著作详情':
                getSoftwareDetail({
                  id: item.id
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    settitle(data.swFname + '的软著信息')
                    setdataList([
                      { label: '生产商', value: data.orgInfoList.map((ele: { companyName: any }) => ele.companyName).join(',') },
                      { label: '软件简称', value: data.swSname || noPublish },
                      { label: '版本', value: data.version || noPublish },
                      { label: '登记号', value: data.regNo || noPublish },
                      { label: '登记批准日期', value: data.approveDate || noPublish },
                      { label: '分类号', value: data.classifyNo || noPublish },
                      { label: '创作完成日期', value: data.completeDate || noPublish },
                      { label: '首次发表时间', value: data.firstPubDate || noPublish },
                      { label: '计算机软件分类号', value: data.softwareTypeNo || noPublish },
                      { label: '计算机软件分类代码', value: data.softwareTypeCode || noPublish },
                      { label: '著作权细分类型', value: data.copyrightSubType || noPublish },
                      { label: '计算机软件分类', value: data.softwareType || noPublish }
                    ])
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              // not yet
              case '备案网站详情':
                getIcpRecordDetail({
                  id: item.id
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    settitle(data.company_name + data.website_list.website_home + '完成备案')
                    setdataList([
                      { label: '企业名称', value: data.company_name || noPublish },
                      { label: '备案号', value: data.website_record || noPublish },
                      { label: '网址', value: data.website_list.website_home || noPublish },
                      { label: '域名', value: data.website_list.website_domain || noPublish },
                      { label: '网站名称', value: data.website_name || noPublish },
                      { label: '审核日期', value: data.audit_date || noPublish }
                    ])
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              case '资质证书详情':
                getCompanyCertDetail({
                  id: item.id
                })
                  .then((res) => {
                    const { data } = res
                    handleEmpty(data)
                    settitle(data.companyName + '获得' + data.certName)
                    setdataList([
                      {
                        label: '公司名称',
                        value: data.companyName || noPublish,
                        type: data.companyCode ? 'link' : '',
                        url: detailUrl(data.companyCode)
                      },
                      { label: '证书名称', value: data.certName || noPublish },
                      { label: '证书编号', value: data.certNo || noPublish },
                      { label: '发证机构', value: data.certOrg || noPublish },
                      { label: '发证日期', value: data.aprvDate || noPublish },
                      { label: '截至日期', value: data.endDate || noPublish },
                      { label: '认证依据', value: data.certBasis || noPublish },
                      { label: '认证范围', value: data.certScope || noPublish }
                    ])
                  })
                  .catch(() => {
                    settitle('')
                    setdataList([])
                  })
                break

              default:
                settitle('')
                setdataList([])
                break
            }
            // end
          }
          setIsModalOpen(true)
        }
      }
    },
    []
  )

  return (
    <Modal title={modalTitle} open={isModalOpen} footer={null} onCancel={handleCancel} width={800}>
      <h3 className="mb-2">{title}</h3>
      {emptyFlag && <Empty />}
      <Descriptions title="" column={4} bordered items={items} labelStyle={{ whiteSpace: 'nowrap' }} />
    </Modal>
  )
}

export default memo(forwardRef(DetailModal))
